package com.gxgeek.springboothive;

/**
 * @author gaoxing
 * @create 2018-06-29 下午5:13
 */

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * JDBC 操作 Hive（注：JDBC 访问 Hive 前需要先启动HiveServer2）
 */
public class HBaseJDBC {

    public static void main(String args[]) {
        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;
        try {
//            Class.forName("io.transwarp.jdbc.InceptorDriver");
            Class.forName("org.apache.hive.jdbc.HiveDriver");
            connection = DriverManager.getConnection("jdbc:hive2:172.19.49.22:60000","","");
            statement = connection.createStatement();
            String sql = "show databases";
            System.out.println("Running: " + sql);
            rs = statement.executeQuery(sql);
            while (rs.next()) {
                System.out.println(rs.getString(1));
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                connection.close();
                statement.close();
                rs.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
